package com.stormragetech.arthas.demo.httpserver.action;

import com.stormragetech.arthas.common.annotation.*;
import com.stormragetech.arthas.demo.httpserver.spring.SpringExecutor;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * description: //TODO
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Log4j2
@Action
@Component
public class TestAction {

    private SpringExecutor executor;

    @Autowired
    public TestAction(SpringExecutor executor) {
        Assert.notNull(executor, "SpringExecutor cannot be null !!!");
        this.executor = executor;
    }

//    @Mapping(url = "/test0", method = RequestType.GET, response = ResponseType.JSON)
    public String doIt() {
        executor.execute();
        return "SUCCESS";
    }

    @Mapping(url = "/test1", method = RequestType.GET, response = ResponseType.JSON)
    public String doIt(@PathParam(name = "id", ness = true) int id) {
        executor.execute();
        log.info("id is {}", id);
        return "SUCCESS " + id;
    }

    @Mapping(url = "/test2", method = RequestType.GET, response = ResponseType.JSON)
    public String doIt(@PathParam(name = "id", ness = true) int id, @PathParam(name = "name", ness = false) String name) {
        executor.execute();
        log.info("id is {}", id);
        log.info("name is {}", name);
        return id + " - " + name;
    }

    @Mapping(url = "/test3", method = RequestType.POST, response = ResponseType.JSON)
    public String doIt(@PathParam(name = "id", ness = true) int userId, Color color) {
        executor.execute();
        return color.toString();
    }
}
